
import 'package:flutter/material.dart';
import 'package:hello_flutter/provider_demo/provider/theme_provider.dart';
import 'package:hello_flutter/provider_demo/provider/user_provider.dart';
import 'package:provider/provider.dart';
import 'first_page.dart';

class MyApp extends StatelessWidget{

  bool isDark = true;
  @override
  Widget build(BuildContext context) {

    return MultiProvider(
      providers: [
//        Provider<ThemeMode>.value(value: ThemeMode.light)
        ChangeNotifierProvider(create: (_) => ThemeProvider()),
        ChangeNotifierProvider(create: (_) => UserProvider(null, null)),
      ],
    child: Consumer<ThemeProvider>(
      builder: (_, provider, __) {
        return MaterialApp(
              title: 'Provider Theme App',
              theme: getTheme(),
              darkTheme: getTheme(isDarkMode: true),
              themeMode: provider.themeMode,
              home: FirstPage()
          );
      })

//      child: MaterialApp(
//          title: 'Provider Theme App',
//          theme: getTheme(),
//          darkTheme: getTheme(isDarkMode: true),
//          themeMode: context.watch<ThemeProvider>().themeMode,
//          home: FirstPage()
//      ),
    );
  }

  ThemeData getTheme({bool isDarkMode = false}) {
    return ThemeData(
//      errorColor: isDarkMode ? Colors.red : Colors.red,
      brightness: isDarkMode ? Brightness.dark : Brightness.light,
      //  主题主色，决定导航栏颜色
      primaryColor: isDarkMode ? DarkColor.PRIMARY_COLOR : AppColor.PRIMARY_COLOR,
      // 主题次色，Widget的颜色，如 FloatingActionButton,进度条、开关等
      accentColor: isDarkMode ? DarkColor.ACCENT_COLOR : AppColor.ACCENT_COLOR,
      backgroundColor: isDarkMode ? DarkColor.BACKGROUND_COLOR : AppColor.BACKGROUND_COLOR,
      scaffoldBackgroundColor: isDarkMode ? DarkColor.BACKGROUND_COLOR : AppColor.BACKGROUND_COLOR,
      // 主要用于Material背景色
      canvasColor: isDarkMode ? DarkColor.BACKGROUND_COLOR : AppColor.BACKGROUND_COLOR,
      // splash color 点击的水纹颜色
      splashColor: isDarkMode ? DarkColor.PRIMARY_COLOR_LIGHT : AppColor.PRIMARY_COLOR_LIGHT,
      // 图标主题
      iconTheme: IconThemeData(
        color: isDarkMode ? DarkColor.TEXT_ICONS_COLOR : AppColor.TEXT_ICONS_COLOR,
      ),
//      appBarTheme: AppBarTheme(
//          elevation: 0.0,
//          color: isDarkMode ? Colors.indigo : Colors.green,
//          brightness: isDarkMode ? Brightness.dark : Brightness.light,
//      ),
      // 分割线的颜色
//      dividerColor: isDarkMode ? Colors.white70 : Colors.amber,
      dividerTheme: DividerThemeData(
          color: isDarkMode ? Colors.white70 : Colors.amber,
          space: 10,
          thickness: 1
      ),

      // Tab指示器颜色
//        indicatorColor: isDarkMode ? Colors.dark_app_main : Colors.app_main,
        // 页面背景色


        // 文字选择色（输入框复制粘贴菜单）
//        textSelectionColor: Colors.app_main.withAlpha(70),
//        textSelectionHandleColor: Colors.app_main,
        textTheme: TextTheme(
          headline6: isDarkMode ? TextStyle(color: DarkColor.PRIMARY_TEXT) : TextStyle(color: AppColor.PRIMARY_TEXT),
          // TextField输入文字颜色
//          subtitle1: isDarkMode ? DarkColor.PRIMARY_TEXT : AppColor.PRIMARY_TEXT,
//          // Text文字样式
//          bodyText2: isDarkMode ? TextStyles.textDark : TextStyles.text,
//          subtitle2: isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
        ),
//        inputDecorationTheme: InputDecorationTheme(
//          hintStyle: isDarkMode ? TextStyles.textHint14 : TextStyles.textDarkGray14,
//        ),
//        cupertinoOverrideTheme: CupertinoThemeData(
//          brightness: isDarkMode ? Brightness.dark : Brightness.light,
//        )
    );
  }

}

class AppColor {
  static Color PRIMARY_COLOR_DARK = Color(0xFF1976D2);
  static Color PRIMARY_COLOR_LIGHT = Color(0xFFBBDEFB);
  static Color PRIMARY_COLOR = Color(0xFF2196F3);
  static Color TEXT_ICONS_COLOR = Color(0xFFFFFFFF);
  static Color ACCENT_COLOR = Color(0xFFFF4081);
  static Color PRIMARY_TEXT = Color(0xFF212121);
  static Color SECONDARY_TEXT = Color(0xFF757575);
  static Color DIVIDER_COLOR = Color(0xFFA0A0A0);
  static Color BACKGROUND_COLOR = Color(0xFFe0FFF0);
}

class DarkColor {
  static Color PRIMARY_COLOR_DARK = Color(0xFF512DA8);
  static Color PRIMARY_COLOR_LIGHT = Color(0xFFD1C4E9);
  static Color PRIMARY_COLOR = Color(0xFF673AB7);
  static Color TEXT_ICONS_COLOR = Color(0xFFF0F4C3);
  static Color ACCENT_COLOR = Color(0xFF009688);
  static Color PRIMARY_TEXT = Color(0xFF448AFF);
  static Color SECONDARY_TEXT = Color(0xFF757575);
  static Color DIVIDER_COLOR = Color(0xFFFFEB3B);
  static Color BACKGROUND_COLOR = Color(0xFF20209f);
}

